﻿//======================================================================
//
//        Copyright : Zhengzhou Strawberry Computer Technology Co.,LTD.
//        All rights reserved
//
//        Application:NFinal MVC framework
//        Filename :TypeTable.cs
//        Description :读取配置对应类型
//
//        created by Lucas at  2015-6-30`
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NFinal.DB.Coding
{
    /// <summary>
    /// 字段类型表
    /// </summary>
    public class TypeTable
    {
        public string fileString = "";
        public TypeTable(NFinal.DB.DBType dbType)
        {
            switch (dbType)
            {
                case DBType.MySql: fileString = NFinal.SqlTemplate.SqlTemplate.mysql; break;
                case DBType.Sqlite: fileString = NFinal.SqlTemplate.SqlTemplate.sqlite; break;
                case DBType.SqlServer: fileString = NFinal.SqlTemplate.SqlTemplate.sqlserver; break;
                case DBType.Oracle: fileString = NFinal.SqlTemplate.SqlTemplate.oracle; break;
                default: fileString = NFinal.SqlTemplate.SqlTemplate.sqlserver; break;
            }

        }
        public Dictionary<string, TypeLink> GetTypeLinks()
        {
            Dictionary<string, TypeLink> links = new Dictionary<string, TypeLink>();
            System.IO.StringReader sr = new System.IO.StringReader(fileString);
            TypeLink link = new TypeLink();
            string[] row;
            string line;
            line = sr.ReadLine();
            row = line.Split('\t');
            while (!string.IsNullOrEmpty(line))
            {
                row = line.Split('\t');
                link = new TypeLink();
                //数据库中的类型
                link.sqlType = row[0].ToLower();
                //csharp 基本类型
                link.localType = row[1];
                //csharp System.Data 中的类型
                link.dbType = row[2];
                //数据转换时所标识的类型
                link.simpleType = row[3];
                links.Add(link.sqlType, link);
                line = sr.ReadLine();
            }
            sr.Close();
            return links;
        }
    }
}
